<template>
    <div>
        <el-table :data="table">
            <el-table-column type="index" />
            <el-table-column v-for="(v,i) in header"
                             :key="i"
                             :prop="v"
                             :label="i"
                             :formatter="Formatter"
            />
        </el-table>
        <pag :total="total" :nosize="nosize" :page-size="10" :page-sizes="[10,20,50,100]"
             @change="Query"
        />
    </div>
</template>

<script>
import pag from '@/components/public/Pagination.vue'
export default {
    components: {
        pag
    },
    props: {
        query: String
    },
    data () {
        return {
            table: [],
            total: 0,
            nosize: 10,
            header: {
                时间: 'createDate',
                操作人: 'userName',
                操作记录: 'modifyInfo'
            }
        }
    },
    computed: {

    },
    watch: {
    },
    created () {
        this.$watch('$parent.visible', val => val && this.Query(), { immediate: true })
    },
    mounted () {
    },
    beforeUpdate () {
    },
    methods: {
        Query ({ pageSize = 20, pageNum = 1 } = {}) {
            const paramType = this.query === 'userLevel' ? 'level' : this.query
            HTTP('查询日志', { paramType, pageSize, pageNum }).then(({ data }) => {
                this.table = data.list || []
                this.total = data.total
                this.nosize = data.pageSize
            })
        },
        Formatter (row, col, val) {
            if (col.label === '时间') {
                return new Date(val * 1000).toLocaleString('zh-cn', { hour12: false })
            }
            return val
        }
    }
}
</script>

<style scoped lang="stylus">

</style>
